package com.casel.yusuke;

import java.util.Timer;



import com.casel.yusuke.WinActivity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.view.animation.LayoutAnimationController;
import android.widget.ImageView;


import android.widget.TextView;
import android.widget.Toast;

import com.example.yusukesshutdown.R;

public class GameActivity extends Activity {
	int contador=0;
	int level;
	String result="";
	String setlevel="";
	TextView contatexto;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		 requestWindowFeature(Window.FEATURE_NO_TITLE);
		 this.getWindow().setFlags(
				 WindowManager.LayoutParams.FLAG_FULLSCREEN,
				  WindowManager.LayoutParams.FLAG_FULLSCREEN);
		TextView player;
		setContentView(R.layout.activity_game);
		player = (TextView) this.findViewById(R.id.player);
		SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(GameActivity.this);
		player.setText(sp.getString("player", "none"));
		setlevel=sp.getString("level", "1");
		
		if(setlevel.contains("1")){
			level=100;
		}else{
			if(setlevel.contains("2")){
				level=175;
			}
		}
		
		final TextView seg = (TextView) this.findViewById(R.id.contasegundos);
		
		
		
       //SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(GameActivity.this);
        //player.setText(sp.getString("player","none"));
		new CountDownTimer(30000, 1000) {	 
		     public void onTick(long millisUntilFinished) {
		    	 
		         seg.setText("TIME: " + millisUntilFinished / 1000);
		     }
		 
		     public void onFinish() {
		         end(contador,level);
		     }
		  }.start();
		     

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.game, menu);
		return true;
		
	}
	public void put(View V){
    	Log.d("CASEL","Opening Another Activity");
	contador++;
 contatexto=(TextView) findViewById(R.id.puntos);
 contatexto.setTextColor(Color.RED);
	result=String.valueOf(contador);
  contatexto.setText(result);
	}
	public void end(int contador,int level){
		
		if(contador >=level){
			
			try{
	 			Class clase= Class.forName("com.casel.yusuke.WinActivity");
	 			Intent intent = new Intent(this, clase);
		 			startActivity(intent);
	    		}catch(ClassNotFoundException e){
	    			e.printStackTrace();
	    		}
		 
        }else{
        	try{
     			Class clase= Class.forName("com.casel.yusuke.LoseActivity");
     			Intent intent = new Intent(this, clase);
    	 			startActivity(intent);
        		}catch(ClassNotFoundException e){
        			e.printStackTrace();
        		}
    	 
        }
			
	}
}
